package com.jqkb;

import android.app.DownloadManager;
import android.content.Context;
import android.graphics.*;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.view.View;

public class DownloadView extends View {
    private int iconType;
    private String url;
    private Bitmap icon;
    private int present;

    public DownloadView(Context context) {
        super(context);
    }

    @Override
    public void draw(Canvas canvas) {
        super.draw(canvas);

        int width = getWidth();
        int height = getHeight();

        canvas.drawBitmap(icon, new Rect(0, 0, icon.getWidth(), icon.getHeight()), new Rect(0, 0, width, height), null);

        if (100 > present && present >= 0) {
            Paint paint = new Paint();
            paint.setColor(0xb0000000);
            canvas.drawRect(new Rect(0, (int) (height * (present / 100f)), width, height), paint);
        }

    }

    public void setIconType(int iconType) {
        this.iconType = iconType;
        this.icon = BitmapFactory.decodeResource(getResources(), iconType);
    }

    public int getIconType() {
        return iconType;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getUrl() {
        return url;
    }

    public int getPresent() {
        return present;
    }

    public void setPresent(int present) {
        this.present = present;
        invalidate();
    }

}
